import Router from'koa-router';
import userAuthed from '../middleware/userAuthed'
import { BASE_URL } from '../config'
import { getUploadToken } from '../utils/qiniu'
import { getImageFaceInfo } from '../utils/openAi'

const marked = require('marked');
const router = new Router();

// ai 说脸开始
router.get('/uploadToken', userAuthed, async (ctx) => {
  ctx.success({ token: getUploadToken() }, '')
});

router.post('/faceInfo', userAuthed, async (ctx) => {
  const { img, text } = ctx.request.body
  const data = await getImageFaceInfo({ url: img, text })
  const content = marked.parse(data.message.content);
  ctx.success({ content }, '')
});
// ai 说脸结束

export const path = `${BASE_URL}/home`
export default router
